#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

//int* minOperations(char* boxes, int* returnSize) {
//    int len = strlen(boxes);
//    //*returnSize = 3;
//    int sum = 0;
//    int count = 0;
//    int* answer = (int*)malloc(sizeof(int) * (len));
//    for (int i = 0; boxes[i] != '\0'; i++)
//    {
//        for (int j = 0; boxes[j] != '\0' && j != i; j++)
//        {
//            if (boxes[i] == 1)
//            {
//                if (boxes[j] == 1)
//                {
//                    sum = j - i;
//                }
//            }
//            count += sum;
//        }
//        answer[i] = count;
//    }
//    return answer;
//}
//
//int main()
//{
//    char* boxes = "110";
//    minOperations(boxes, 3);
//	return 0;
//}


char* restoreString(char* s, int* indices, int indicesSize) {
    char* ret = (char*)malloc(sizeof(char) * (indicesSize));
    int gps = 0;
    int j = 0;
    int i = 0;
    while (gps != indicesSize)
    {
        if (gps == indices[j++])
        {
            i = j;//
            ret[gps++] = s[j];
            j = 0;
        }
    }
    return ret;
}

int main()
{
    char* s = "codeleet";
    int indices[] = {4, 5, 6, 7, 0, 2, 1, 3};
    char* ret = restoreString(s, indices, 8);
    int len = strlen(ret);
    printf("%d", len);
    printf("%s", ret);
    return 0;
}